package com.richesup.common.oss.service.impl;/**
 * @Auther: yuhong
 * @Date: 2018-6-26 17:40
 * @Description:
 */

import com.richesup.common.oss.common.CodeMessage;
import com.richesup.common.oss.common.OSSException;
import com.richesup.common.oss.common.ResultEntity;
import com.richesup.common.oss.dao.AppMapper;
import com.richesup.common.oss.service.IApp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author yuhong
 * @date 2018-06-26 17:40
 * @description
 */
@Service
public class App implements IApp {

    @Autowired
    AppMapper appMapper;

    @Override
    public com.richesup.common.oss.entity.App verifyApp(String app_id,String app_secret) {
        if (app_id==null ||app_id.equals("")) throw new OSSException(ResultEntity.error(CodeMessage.PARAMETER_ISNULL));
        if (app_secret==null ||app_secret.equals(""))  throw new OSSException(ResultEntity.error(CodeMessage.PARAMETER_ISNULL));
        com.richesup.common.oss.entity.App app= appMapper.selectByPrimaryKey(app_id);

        if (app==null || !app.getApp_secret().equals(app_secret)){
            throw new OSSException(ResultEntity.error(CodeMessage.PERMISSION_DENIED));
        }
        return app;
    }
}
